class FieldValidator{
    /**
     * @param {string} inputID 
     * @param {Function} checkFunc
     */
    constructor(inputID,checkFunc){
        this.input=document.querySelector(`#${inputID}`);
        this.errInput=this.input.nextElementSibling;
       this.checkFunc=checkFunc;
       this.input.onblur=()=>{
        this.runCheck();
       }
    }
    async  runCheck() {
        const err=await this.checkFunc(this.input.value);
        if(err){
            this.errInput.innerText=err;
            return false;
        }else{
            this.errInput.innerText='';
            return true;
        }
    }
    /**
     * 
     * @param  {FieldValidator[]} arr 
     */
    static async runAllcheck(...arr){
        const proms=arr.map(item=>item.runCheck());
        const results= await Promise.all(proms);
        return results.every(v=>v);
    }
}
